package com.chanyachting.emall.action.companyproduct;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Companyproduct;
import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.domain.ServiceOptionType;
import com.chanyachting.emall.service.CompanyproductService;
import com.chanyachting.emall.service.MemberService;
import com.chanyachting.emall.serviceImpl.CompanyproductServiceImpl;
import com.chanyachting.emall.serviceImpl.MemberorderservicesBO;
import com.chanyachting.emall.util.DateUtil;
import com.chanyachting.emall.util.RequestUtil;

public class ReleaseAction extends Action {
	
	
	//上架普通商品
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		int cpid=Integer.parseInt(ru.getParameter("cpid", "0"));

		Companyproduct cp=new Companyproduct(cpid);
		
		if(cp!=null){
			
			//检查会员是否有对应服务
			Member member=(Member)ru.getSessionObject(MemberService.MEMBER_IN_SESSION,new Member());
			
			String optionType=ServiceOptionType.Product_Shelves;
			
			boolean temp=MemberorderservicesBO.checkMmemberServiceByMemberAndOPType(member, optionType);
			
			if(temp){
				
				cp.setStatus("01");
				cp.setUpdateDate(DateUtil.getDate());
				
			}else{
				
				ru.setMsg("发布展示失败！请确认已经购买/开启产品上架服务。");
				
				return mapping.findForward("nomalProductList");
			}
			
			
			if(cp.update()){
				
				ru.setSuccessMsg();
			}else{
				
				ru.setFailMsg();
			}
		}
		
		return mapping.findForward("nomalProductList");
	}

}
